#include <iostream>
#include <cmath>
using namespace std;

class Point
{
public:
    Point();
    Point(float _x, float _y);
    void setLocation(float _x, float _y);
    float getX();
    float getY();
    ~Point();

private:
    float x;
    float y;
};
class Rectangle
{
public:
    Rectangle();
    ~Rectangle();
    void getVertexCoordinate();
    void setVertices(Point _p1, Point _p2, Point _p3, Point _p4);
    float getArea();
    bool isRectangle();

private:
    Point p1;
    Point p2;
    Point p3;
    Point p4;
};

Point::Point()
{
    this->x = 0;
    this->y = 0;
}
Point::Point(float _x, float _y)
{
    this->x = _x;
    this->y = _y;
}
Point::~Point()
{
}
float Point::getX()
{
    return this->x;
}
float Point::getY()
{
    return this->y;
}
void Point::setLocation(float _x, float _y)
{
    this->x = _x;
    this->y = _y;
}
Rectangle::Rectangle()
{
}

Rectangle::~Rectangle()
{
}
void Rectangle::setVertices(Point _p1, Point _p2, Point _p3, Point _p4)
{
    // 如果能构成矩形，设置矩形的四个顶点
    this->p1 = _p1;
    this->p2 = _p2;
    this->p3 = _p3;
    this->p4 = _p4;
}

bool Rectangle::isRectangle()
{
    // 计算四条边的长度的平方
    float d1 = pow(p1.getX() - p2.getX(), 2) + pow(p1.getY() - p2.getY(), 2);
    float d2 = pow(p2.getX() - p3.getX(), 2) + pow(p2.getY() - p3.getY(), 2);
    float d3 = pow(p3.getX() - p4.getX(), 2) + pow(p3.getY() - p4.getY(), 2);
    float d4 = pow(p4.getX() - p1.getX(), 2) + pow(p4.getY() - p1.getY(), 2);

    // 计算对角线的长度的平方
    float diagonal1 = pow(p1.getX() - p3.getX(), 2) + pow(p1.getY() - p3.getY(), 2);
    float diagonal2 = pow(p2.getX() - p4.getX(), 2) + pow(p2.getY() - p4.getY(), 2);

    // 判断相对的边是否相等，并且对角线是否相等
    if ((d1 == d3 && d2 == d4) && (diagonal1 == diagonal2))
    {
        return true;
    }
    else
    {
        return false;
    }
}

void Rectangle::getVertexCoordinate()
{
    cout << "矩形顶点坐标：" << endl;
    cout << "P1(" << p1.getX() << ", " << p1.getY() << ")" << endl;
    cout << "P2(" << p2.getX() << ", " << p2.getY() << ")" << endl;
    cout << "P3(" << p3.getX() << ", " << p3.getY() << ")" << endl;
    cout << "P4(" << p4.getX() << ", " << p4.getY() << ")" << endl;
}
float Rectangle::getArea()
{
    // 计算矩形的宽度和长度
    float width = abs(p1.getY() - p2.getY());
    float length = abs(p2.getX() - p3.getX());

    // 矩形的面积为宽度乘以长度
    return width * length;
}

int main()
{
    float x, y;

    // 输入四个点的坐标
    cout << "请输入四个点的坐标（格式：x y）：" << endl;
    cin >> x >> y;
    Point p1(x, y);
    cin >> x >> y;
    Point p2(x, y);
    cin >> x >> y;
    Point p3(x, y);
    cin >> x >> y;
    Point p4(x, y);
    // 检查四个点是否互不重合
    if (p1.getX() == p2.getX() && p1.getY() == p2.getY() &&
        p1.getX() == p3.getX() && p1.getY() == p3.getY() &&
        p1.getX() == p4.getX() && p1.getY() == p4.getY())
    {
        cout << "四个点坐标重合，请重新输入。" << endl;
        return 1;
    }

    // 创建矩形对象
    Rectangle rectangle;
    rectangle.setVertices(p1, p2, p3, p4);

    if (rectangle.isRectangle())
    {
        // 输出矩形的顶点坐标
        rectangle.getVertexCoordinate();
        // 输出矩形的面积
        cout << "矩形的面积为：" << rectangle.getArea() << endl;
    }
    else
    {
        cout << "四个点无法构成矩形。" << endl;
    }

    return 0;
}
